
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class Principal extends javax.swing.JFrame {    /** Creates new form Principal */
imagenprincipal ip = new imagenprincipal();
    BD bd = new BD();
    public Principal() {
      
initComponents();setLocation(150,70);bd.configurar();setTitle("Software Control de Clientes");
setResizable(false);jButton2.setToolTipText("Actualizar Datos");this.TablaEvaluaciones();
      add(ip,BorderLayout.CENTER);jButton5.setToolTipText("Actualizar Tabla");jButton3.setToolTipText("Agregar Cliente");jButton4.setToolTipText("Eliminar Cliente");}
    public Icon getIcon2(){
        return new ImageIcon(getClass().getResource("/Imagenes/db_remove.png"));}
     public Icon getIcon3(){
        return new ImageIcon(getClass().getResource("/Imagenes/db_remove.png"));}



public void TablaEvaluaciones() {

        DefaultTableModel model = new DefaultTableModel();
        List<String> mostrarclientes[] = bd.mostrarLista();

     model.addColumn("Num Reg");
     model.addColumn("Nombre");
     model.addColumn("Apellido P");
     model.addColumn("Apellido M");
     model.addColumn("Telefono");
     model.addColumn("Celular");
     model.addColumn("Edad");
     model.addColumn("Domicilio");
     model.addColumn("Fecha de Nacimiento");
     model.addColumn("Total a Pagar");
     model.addColumn("Anticipo");
     model.addColumn("Saldo");
     model.addColumn("Ultima Modificacion");
     model.addColumn("Caso");
     model.addColumn("Observaciones");
    
     jTable1.setModel(model);

     int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,cont=1;

    for (String numero : mostrarclientes[0]) {
        model.addRow(new Object[]{cont});
        cont=cont+1;
        }
   for (String nom : mostrarclientes[0] ) {
            jTable1.setValueAt(nom, a ,0);
           a=a+1; }

 for (String nom : mostrarclientes[1] ) {
           jTable1.setValueAt(nom, b ,1);
           b=b+1; }

       for (String nom : mostrarclientes[2] ) {
           jTable1.setValueAt(nom, c ,2);
           c=c+1; }

        for (String nom : mostrarclientes[3] ) {
           jTable1.setValueAt(nom, d ,3);
           d=d+1; }

         for (String nom : mostrarclientes[4] ) {
           jTable1.setValueAt(nom, e ,4);
           e=e+1; }

          for (String nom : mostrarclientes[5] ) {
           jTable1.setValueAt(nom, f ,5);
           f=f+1; }

     for (String nom : mostrarclientes[7] ) {
           jTable1.setValueAt(nom, g ,6);
           g=g+1; }

        for (String nom : mostrarclientes[8] ) {
           jTable1.setValueAt(nom, h ,7);
           h=h+1; }

          for (String nom : mostrarclientes[9] ) {
           jTable1.setValueAt(nom, i ,8);
           i=i+1; }

       for (String nom : mostrarclientes[14] ) {
           jTable1.setValueAt(nom, j ,9);
           j=j+1; }

         for (String nom : mostrarclientes[10] ) {
           jTable1.setValueAt(nom, k ,10);
           k=k+1; }

          for (String nom : mostrarclientes[11] ) {
           jTable1.setValueAt(nom, l ,11);
           l=l+1; }

  for (String nom : mostrarclientes[12] ) {
           jTable1.setValueAt(nom, m ,12);
           m=m+1; }
         for (String nom : mostrarclientes[6] ) {
           jTable1.setValueAt(nom, n ,13);
           n=n+1; }
 for (String nom : mostrarclientes[13] ) {
           jTable1.setValueAt(nom, o ,14);
           o=o+1; }
       
    


       
        
 }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jTable1MouseEntered(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTable1MousePressed(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTabbedPane1.addTab("Casos Registrados", jScrollPane1);

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Busqueda");

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Apellido:");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/find.png"))); // NOI18N
        jButton1.setText("Buscar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/add_user.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/db_remove_1.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/reload_all_tabs.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/db_update.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jMenu1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/fileopen.png"))); // NOI18N
        jMenu1.setText("Archivo");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/add_userp.png"))); // NOI18N
        jMenuItem1.setText("Agregar Caso");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/edit_user.png"))); // NOI18N
        jMenuItem2.setText("Entrar Como Cliente");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1057, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(141, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jButton2))
                .addGap(4, 4, 4)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)
                    .addComponent(jLabel2)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
AgregarCliente ac = new AgregarCliente();
ac.setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed



// TODO add your handling code here:
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
 AgregarCliente ac = new AgregarCliente();
ac.setVisible(true);         // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
 try{
        JOptionPane.showMessageDialog(null,"Cliente Eliminado(a)","Eliminar",JOptionPane.PLAIN_MESSAGE,getIcon2());
          String g=(String) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 1);
          List<String> cliente = bd.Eliminar(g);
          this.TablaEvaluaciones();
 }
catch(Exception e){
    JOptionPane.showMessageDialog(null,"Seleccione un cliente a eliminar");
}
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
this.TablaEvaluaciones();        // TODO add your handling code here:
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
    }//GEN-LAST:event_jTable1MouseClicked

    private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed
    
    }//GEN-LAST:event_jTable1MousePressed

    private void jTable1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseEntered
            // TODO add your handling code here:
    }//GEN-LAST:event_jTable1MouseEntered

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed

        int x=jTable1.getSelectedRow();
       String Dato1=(String) jTable1.getModel().getValueAt(x,0);
       String Dato2=(String) jTable1.getModel().getValueAt(x,1);
       String Dato3=(String) jTable1.getModel().getValueAt(x,2);
       String Dato4=(String) jTable1.getModel().getValueAt(x,3);
       String Dato5=(String) jTable1.getModel().getValueAt(x,4);
       String Dato6=(String) jTable1.getModel().getValueAt(x,5);
       String Dato7=(String) jTable1.getModel().getValueAt(x,6);
       String Dato8=(String) jTable1.getModel().getValueAt(x,7);
       String Dato9=(String) jTable1.getModel().getValueAt(x,8);
       String Dato10=(String) jTable1.getModel().getValueAt(x,9);
       String Dato11=(String) jTable1.getModel().getValueAt(x,10);
       String Dato12=(String) jTable1.getModel().getValueAt(x,11);
       String Dato13=(String) jTable1.getModel().getValueAt(x,12);
       String Dato14=(String) jTable1.getModel().getValueAt(x,13);
        String Dato15=(String) jTable1.getModel().getValueAt(x,14);

      JOptionPane.showMessageDialog(null,"Datos del Cliente"+"\n Numero de Registro:  "+Dato1+"\n Nombre:  "+Dato2+"\n Apellido Paterno:  "+Dato3+"\n Apellido Materno:  "+Dato4+"\n Telefono:  "+Dato5+
"\n Celular:  "+Dato6+"\n Edad:  "+Dato7+"\n Domicilio:  "+Dato8+"\n Total a Pagar:  "+Dato9+"\n Anticipo:  "+Dato10+
              "\n Saldo:  "+Dato11+"\n Fecha de Alta:  "+Dato12+"\n Fecha de Nacimiento:  "+Dato13+"\n Caso:  "+Dato14+"\n Observaciones:  "+Dato15);
calculos();

         // TODO add your handling code here:
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable1KeyPressed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

int columna=jTable1.getSelectedColumn();


String colum_select="";
if(columna==0){JOptionPane.showMessageDialog(null," no se puede modificar el registro ");}
if(columna==1){colum_select="nombre";}
if(columna==2){colum_select="apellidop";}
if(columna==3){colum_select="apellidom";}
if(columna==4){colum_select="tel";}
if(columna==5){colum_select="cel";}
if(columna==6){colum_select="domicilio";}
if(columna==7){colum_select="totalpagar";}
if(columna==8){colum_select="anticipo";}//
if(columna==9){colum_select="saldo";}
if(columna==10){colum_select="fechaalta";}
if(columna==11){colum_select="fechanacimniento";}
if(columna==12){colum_select="caso";}
if(columna==13){colum_select="edad";}
if(columna==14){colum_select="observaciones";}
/*
    int fila = jTable1.getSelectedRow();
    String total = (String) jTable1.getModel().getValueAt(fila,9);
    String anticipo = (String) jTable1.getModel().getValueAt(fila,10);*/
String Dato_amodificar=(String) jTable1.getModel().getValueAt(jTable1.getSelectedRow(),jTable1.getSelectedColumn());
String dato_nuevo=JOptionPane.showInputDialog("modificar dato "+Dato_amodificar +" por ");
 int x=jTable1.getSelectedRow();
       String registro=(String) jTable1.getModel().getValueAt(x,0);
   bd.Modificar(dato_nuevo,registro,colum_select);
   //JOptionPane.showInputDialog(dato_nuevo+","+registro+","+colum_select);
   this.TablaEvaluaciones();




        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed
public void calculos(){
    int fila = jTable1.getSelectedRow();
    String total = (String) jTable1.getModel().getValueAt(fila,9);
    String anticipo = (String) jTable1.getModel().getValueAt(fila,10);
    int x = Integer.parseInt(total);
    int y = Integer.parseInt(anticipo);
    int w;
    w=x-y;
jTable1.setValueAt(w, 11, fila);

}
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
String x = jTextField1.getText();
  List<String> mostrarclientes[] = bd.busqueda(x);
  DefaultTableModel model = new DefaultTableModel();

     model.addColumn("Num Reg");
     model.addColumn("Nombre");
     model.addColumn("Apellido P");
     model.addColumn("Apellido M");
     model.addColumn("Telefono");
     model.addColumn("Celular");
     model.addColumn("Edad");
     model.addColumn("Domicilio");
     model.addColumn("Fecha de Nacimiento");
     model.addColumn("Total a Pagar");
     model.addColumn("Anticipo");
     model.addColumn("Saldo");
     model.addColumn("Ultima Modificacion");
     model.addColumn("Caso");
     model.addColumn("Observaciones");

     jTable1.setModel(model);

     int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,cont=1;

    for (String numero : mostrarclientes[0]) {
        model.addRow(new Object[]{cont});
        cont=cont+1;
        }
   for (String nom : mostrarclientes[0] ) {
            jTable1.setValueAt(nom, a ,0);
           a=a+1; }

 for (String nom : mostrarclientes[1] ) {
           jTable1.setValueAt(nom, b ,1);
           b=b+1; }

       for (String nom : mostrarclientes[2] ) {
           jTable1.setValueAt(nom, c ,2);
           c=c+1; }

        for (String nom : mostrarclientes[3] ) {
           jTable1.setValueAt(nom, d ,3);
           d=d+1; }

         for (String nom : mostrarclientes[4] ) {
           jTable1.setValueAt(nom, e ,4);
           e=e+1; }

          for (String nom : mostrarclientes[5] ) {
           jTable1.setValueAt(nom, f ,5);
           f=f+1; }

     for (String nom : mostrarclientes[7] ) {
           jTable1.setValueAt(nom, g ,6);
           g=g+1; }

        for (String nom : mostrarclientes[8] ) {
           jTable1.setValueAt(nom, h ,7);
           h=h+1; }

          for (String nom : mostrarclientes[9] ) {
           jTable1.setValueAt(nom, i ,8);
           i=i+1; }

       for (String nom : mostrarclientes[14] ) {
           jTable1.setValueAt(nom, j ,9);
           j=j+1; }

         for (String nom : mostrarclientes[10] ) {
           jTable1.setValueAt(nom, k ,10);
           k=k+1; }

          for (String nom : mostrarclientes[11] ) {
           jTable1.setValueAt(nom, l ,11);
           l=l+1; }

  for (String nom : mostrarclientes[12] ) {
           jTable1.setValueAt(nom, m ,12);
           m=m+1; }
         for (String nom : mostrarclientes[6] ) {
           jTable1.setValueAt(nom, n ,13);
           n=n+1; }
 for (String nom : mostrarclientes[13] ) {
           jTable1.setValueAt(nom, o ,14);
           o=o+1; }






    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
cliente c = new cliente();
c.setVisible(true);
dispose();



    }//GEN-LAST:event_jMenuItem2ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
